﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DX.engine.exceptions;

namespace DX.engine
{
    public class EngineSettings
    {
        private Dictionary<string, bool> _boolSettings;
        private Dictionary<string, int> _intSettings;
        private Dictionary<string, float> _floatSettings;
        private Dictionary<string, string> _stringSettings;
        
        public EngineSettings()
        {
            _boolSettings = new Dictionary<string, bool>();
            _intSettings = new Dictionary<string, int>();
            _stringSettings = new Dictionary<string, string>();
            _floatSettings = new Dictionary<string, float>();
        }

        public bool FetchBoolSetting(string settingName)
        {
            if (!_boolSettings.ContainsKey(settingName))
                throw new SettingNotFoundException(settingName);
            return _boolSettings[settingName];
        }

        public int FetchIntSetting(string settingName)
        {
            if (!_intSettings.ContainsKey(settingName))
                throw new SettingNotFoundException(settingName);
            return _intSettings[settingName];
        }

        public float FetchFloatSetting(string settingName)
        {
            if (!_floatSettings.ContainsKey(settingName))
                throw new SettingNotFoundException(settingName);
            return _floatSettings[settingName];
        }

        public string FetchStringSetting(string settingName)
        {
            if (!_stringSettings.ContainsKey(settingName))
                throw new SettingNotFoundException(settingName);
            return _stringSettings[settingName];
        }

        public void AddSetting(string settingName, object val)
        {
            if (val is int)
                _intSettings.Add(settingName, (int)val);
            else if (val is bool)
                _boolSettings.Add(settingName, (bool)val);
            else if (val is string)
                _stringSettings.Add(settingName, (string)val);
            else
                throw new InvalidSettingTypeException(settingName, val);
        }


    }
}
